﻿using HCQ2_Common;
using HCQ2_Common.Constant;
using HCQ2_Model;
using HCQ2_Model.DocModel.APIParam;
using HCQ2_Model.ViewModel.WebAPI;
using HCQ2_Model.VLine.InputDto._0410;
using HCQ2_Model.VLine.InputDto._0416;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VLine.OutputDto._0416;
using HCQ2_Model.VLine.Params;
using HCQ2_Model.VR;
using HCQ2_Model.VRDD.InputDto;
using HCQ2_Model.VRDD.InputDto._0427;
using HCQ2_Model.VRDD.InputDto._0531;
using HCQ2_Model.VRDD.InputDto._211217;
using HCQ2_Model.VRDD.OutputDto._0427;
using HCQ2_Model.VRDD.OutputDto._0525;
using HCQ2UI_Helper.Session;
using HCQ2WebAPI_Logic.BaseAPIController;
using HCQ2WebAPI_Logic.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace HCQ2WebAPI_Logic.DocumentController
{
    /// <summary>
    ///  VR度度圈【2021-04-27】【2021-05-31】需求
    /// </summary>
    public class VRDDRingController : BaseWeiXinApiLogic
    {
        //****************************************************2021-04-27需求*******************************************************
        #region 1.1 ✔获取我的人脉 + WebApiResultJsonModel GetMyConnection(QueryMyConnection param)
        /// <summary>
        ///  1.1 ✔获取我的人脉
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、禅道需求 id=【337】2022-06-14<br/>
        /// 2、禅道需求 id=【340】2022-06-20<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<OutMyConnection>> GetMyConnection(QueryMyConnection param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(param.user_id<=0 && string.IsNullOrEmpty(param.userid))
                return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Exception, "登录用户user_id、userid不能同时为空!", null);
            if (!string.IsNullOrEmpty(param.userid))
            {
                var u = operateContext.bllSession.T_User.FindSingle(s => s.user_guid == param.userid);
                if(u==null)
                    return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Exception, "当前登录用户编码后台不存在！", null);
                param.user_id = u.user_id;
            }
            else
            {
                int mark = operateContext.bllSession.T_User.SelectCount(s => s.user_id == param.user_id);
                if (mark <= 0)
                    return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Exception, "当前登录对象后台不存在！", null);
            }
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if(user==null)
                return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息！", null);
            List<OutMyConnection> list = operateContext.bllSession.DD_FriendApply.GetMyConnection(param, user);
            return ApiResultJsonModel<List<OutMyConnection>>.RedirectWebApi(WebResultCode.Ok, "成功获取我的人脉~", list);
        }
        #endregion

        #region 1.2 ✔获取人脉详情 + WebApiResultJsonModel GetConnectionDetial(QueryConnectionDetial param)
        /// <summary>
        ///  1.2 ✔获取人脉详情
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-31 需求文档【1.5】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<OutConnectionDetial> GetConnectionDetial(QueryConnectionDetial param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(string.IsNullOrEmpty(param.userid) && param.user_id<=0)
                return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, "userid、user_id不允许同时为空！", null);
            if(param.du_id<=0 && string.IsNullOrEmpty(param.duCode))
                return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, "duCode、du_id不允许同时为空！", null);
            if (!string.IsNullOrEmpty(param.userid)){
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
                if(param.user_id<=0)
                    return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, "请检查传递的userid信息异常错误！", null);
            }
            if (!string.IsNullOrEmpty(param.duCode))
            {
                param.du_id= SysPermissSession.ChangeIdByGuid(param.duCode);
                if (param.du_id <= 0)
                    return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, "请检查传递的duCode信息异常错误！", null);
            }         
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息！", null);
            string userId = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id)?.user_guid,
                ddId = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.du_id)?.user_guid;
            OutConnectionDetial result = operateContext.bllSession.DD_FriendApply.GetConnectionDetial(param,userId,ddId);
            return ApiResultJsonModel<OutConnectionDetial>.RedirectWebApi(WebResultCode.Ok, "成功获取人脉详情~", result);
        }
        #endregion

        #region 1.3 ✔获取我的好友【通讯录】 + WebApiResultJsonModel GetMyFriend(DDBaseUser param)
        /// <summary>
        ///  1.3 ✔获取我的好友【通讯录】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-31 需求文档 【1.4】<br/>
        /// 2、禅道需求 【id=334】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<OutMyFriend>> GetMyFriend(DDBaseUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutMyFriend>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (string.IsNullOrEmpty(param.userid) && param.user_id <= 0)
                return ApiResultJsonModel<List<OutMyFriend>>.RedirectWebApi(WebResultCode.Exception, "userid、user_id不允许同时为空！", null);
            if (!string.IsNullOrEmpty(param.userid))
            {
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
                if (param.user_id <= 0)
                    return ApiResultJsonModel<List<OutMyFriend>>.RedirectWebApi(WebResultCode.Exception, "请检查传递的userid信息异常错误！", null);
            }
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel<List<OutMyFriend>>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息！", null);
            List<OutMyFriend> list = operateContext.bllSession.DD_FriendApply.GetMyFriend(param);
            return ApiResultJsonModel<List<OutMyFriend>>.RedirectWebApi(WebResultCode.Ok, "成功获取我的好友列表~", list);
        }
        #endregion

        #region 1.4 ✔获取我的信息 + WebApiResultJsonModel GetMyInfo(MyBaseUser param)
        /// <summary>
        ///  1.4 ✔获取我的信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<OutMyInfo> GetMyInfo(MyBaseUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutMyInfo>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (string.IsNullOrEmpty(param.userid) && param.user_id <= 0)
                return ApiResultJsonModel<OutMyInfo>.RedirectWebApi(WebResultCode.Exception, "userid、user_id不允许同时为空！", null);
            if (!string.IsNullOrEmpty(param.userid))
            {
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
                if (param.user_id <= 0)
                    return ApiResultJsonModel<OutMyInfo>.RedirectWebApi(WebResultCode.Exception, "请检查传递的userid信息异常错误！", null);
            }
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel<OutMyInfo>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息！", null);
            string user_guid = string.IsNullOrEmpty(param.userid) ? operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id)?.user_guid : param.userid;
            OutMyInfo result = operateContext.bllSession.DD_User.GetMyInfo(param,user_guid);
            return ApiResultJsonModel<OutMyInfo>.RedirectWebApi(WebResultCode.Ok, "成功获取我的信息~", result);
        }
        #endregion

        #region 1.5 ✔保存访客记录 + WebApiResultJsonModel AddVisitorRecord(AddVisitorRecord param)
        /// <summary>
        ///  1.5 ✔保存访客记录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddVisitorRecord(AddVisitorRecord param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (string.IsNullOrEmpty(param.userid) && param.user_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "userid、user_id不允许同时为空！", null);
            if (!string.IsNullOrEmpty(param.userid))
            {
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
                if (param.user_id <= 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "请检查传递的userid信息异常错误！", null);
            }
            //var obj = operateContext.bllSession.DD_Visit.FindSingle(s => s.visitor_id == param.user_id && s.du_id == param.id);
            //if (obj != null)
            //{
            //    obj.created_time = DateTime.Now;
            //    obj.confirm_status = false;
            //    operateContext.bllSession.DD_Visit.Modify(obj, s => s.primary_key == obj.primary_key, "created_time", "confirm_status");
            //    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "访客记录保存成功~", "");
            //}
            int mark = operateContext.bllSession.DD_Visit.Add(new DD_Visit
            {
                visitor_id = param.user_id,
                du_id = param.id,
                created_time = DateTime.Now,
                confirm_status = false
            });
            if (mark > 0)
            {
                //更新访问记录统计
                var u = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.id);
                u.count_visitor = u.count_visitor + 1;
                operateContext.bllSession.DD_User.Modify(u, s => s.du_id == u.du_id, "count_visitor");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "访客记录保存成功~", "");
            }     
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "访客记录保存失败~", null);
        }
        #endregion

        #region 1.6 ✔提交好友申请 + WebApiResultJsonModel ApplyFriend(AddApplyFriend param)
        /// <summary>
        ///  1.6 ✔提交好友申请
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ApplyFriend(AddApplyFriend param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(param.user_id==param.id)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "不能添加自己为好友！", null);
            var o= operateContext.bllSession.DD_User.SelectCount(s => s.du_id == param.user_id);
            if (o <= 0)
            {
                operateContext.bllSession.DD_User.Add(new DD_User
                {
                    du_id = param.user_id,
                    du_city_id = 0,
                    du_hometown_id = 0,
                    du_sex = 0,
                    count_fan = 0,
                    count_friend = 0,
                    count_visited = 0,
                    count_visitor = 0,
                    dd_verify = true,
                    dd_hidden = false,
                    hide_name = 2,
                    hide_sex = 2,
                    hide_mobile = 2,
                    hide_birthday = 2,
                    hide_city = 2,
                    hide_hometown = 2,
                    created_time = DateTime.Now
                });
            }
            o = operateContext.bllSession.DD_User.SelectCount(s => s.du_id == param.id);
            if (o <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "该都都圈用户不存在！", null);
            var obj = operateContext.bllSession.DD_FriendApply.FindSingle(s => (s.apply_id == param.user_id && s.du_id == param.id) || (s.apply_id == param.id && s.du_id == param.user_id));
            if (obj != null)
            {
                if (obj.apply_status==-1)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "已申请等待对方处理中，请不要重复申请！", null);
                if(obj.apply_status==1)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "您已和对方是好友无需重复申请！", null);
            }
            int mark = operateContext.bllSession.DD_FriendApply.Add(new DD_FriendApply
            {
                apply_id = param.user_id,
                du_id = param.id,
                created_time = DateTime.Now,
                apply_note = param.apply_note,
                apply_from = param.apply_from,
                apply_status = -1,
                confirm_status = false
            });
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "申请成功~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "申请失败~", null);
        }
        #endregion

        #region 1.7 ✔获取好友申请 + WebApiResultJsonModel GetApplyFirend(DDBaseUser param)
        /// <summary>
        ///  1.7 ✔获取好友申请
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiResultJsonModel<List<OutApplyFriend>>> GetApplyFirend(DDBaseUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutApplyFriend>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            List<OutApplyFriend> list = await operateContext.bllSession.DD_FriendApply.GetApplyFirend(param);
            return ApiResultJsonModel<List<OutApplyFriend>>.RedirectWebApi(WebResultCode.Ok, "成功获取好友申请列表~", list);
        }
        #endregion

        #region 1.8 ✔处理好友申请 + WebApiResultJsonModel ApproveFirendApply(ApproveFriendApply param)
        /// <summary>
        ///  1.8 ✔处理好友申请
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.1需求<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel ApproveFirendApply(ApproveFriendApply param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var query = operateContext.bllSession.DD_FriendApply.FindSingle(s => s.primary_key == param.primary_key);
            if(query==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, $"当前申请id【{param.primary_key}】后台不存在！", null);
            query.apply_status = param.apply_status;
            query.apply_time = DateTime.Now;
            int mark = operateContext.bllSession.DD_FriendApply.Modify(query, s => s.primary_key == param.primary_key, "apply_status", "apply_time");
            if (param.apply_status == 1)
            {
                //d1：申请人、d2：好友
                int d1 = query.apply_id, d2 = query.du_id;
                //判断是否为重复处理
                var friend = operateContext.bllSession.DD_1.Select(s => (s.dd_id_1 == d1 && s.dd_id_2 == d2) || (s.dd_id_1 == d2 && s.dd_id_2 == d1));
                //自己申请情况
                var fCount = friend.Where(s => s.dd_id_1 == d1 && s.dd_id_2 == d2)?.ToList()?.Count;
                if (fCount == null || fCount <= 0)
                {
                    //添加好友【自己情况】
                    var u = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == query.apply_id);
                    u.count_friend = u.count_friend + 1;
                    operateContext.bllSession.DD_User.Modify(u, s => s.du_id == u.du_id, "count_friend");
                    //同意好友申请同时写入一度好友表                
                    operateContext.bllSession.DD_1.Add(new DD_1 { dd_id_1 = d1, dd_id_2 = d2, isfriend = true });
                }
                else
                    operateContext.bllSession.DD_1.Modify(new DD_1 { isfriend = true }, s => s.dd_id_1 == d1 && s.dd_id_2 == d2, "isfriend");
                //对方情况
                fCount = friend.Where(s => s.dd_id_1 == d2 && s.dd_id_2 == d1)?.ToList()?.Count;
                if(fCount == null || fCount <= 0)
                {
                    //添加好友【对方情况】
                    var p = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == query.du_id);
                    p.count_friend = p.count_friend + 1;
                    operateContext.bllSession.DD_User.Modify(p, s => s.du_id == p.du_id, "count_friend");
                    //同意好友申请同时写入一度好友表                
                    operateContext.bllSession.DD_1.Add(new DD_1 { dd_id_1 = d2, dd_id_2 = d1, isfriend = true });
                }else
                    operateContext.bllSession.DD_1.Modify(new DD_1 { isfriend = true }, s => s.dd_id_1 == d2 && s.dd_id_2 == d1, "isfriend");
                //自动更新2度、3度人脉
                operateContext.bllSession.DD_FriendApply.UpdateDD2(d1, d2);
            }                
            if(mark>0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "处理好友申请成功~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "处理好友申请失败！", null);
        }
        #endregion

        #region 1.9-1 ✔保存关注记录 + WebApiResultJsonModel SaveAttention(AddAttention param)
        /// <summary>
        ///  1.9-1 ✔保存关注记录【仅限度度圈】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveAttention(AddAttention param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var obj = operateContext.bllSession.DD_Fans.FindSingle(s => s.fan_id == param.user_id && s.du_id == param.id && !s.if_remove);
            if (param.fan_status == 0)
            {
                if (obj == null)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "未关注过无需取消！", null);
                obj.if_remove = true;
                obj.delete_time = DateTime.Now;
                operateContext.bllSession.DD_Fans.Modify(obj, s => s.primary_key == obj.primary_key, "if_remove", "delete_time");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消关注成功！", "");
            }
            if (obj != null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "已关注无需重复关注！", "");
            int mark = operateContext.bllSession.DD_Fans.Add(new DD_Fans
            {
                fan_id = param.user_id,
                du_id = param.id,
                created_time = DateTime.Now
            });
            if (mark > 0)
            {
                //更新被关注数统计
                var u = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.id);
                u.count_fan = u.count_fan + 1;
                operateContext.bllSession.DD_User.Modify(u, s => s.du_id == u.du_id, "count_fan");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "关注成功！", "");
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "关注失败！", "");
        }
        #endregion

        #region 1.9-2 ✔保存用户点赞 + WebApiResultJsonModel SaveStar(StarParam param)
        /// <summary>
        ///  1.9-2 ✔保存用户点赞【仅限度度圈】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveStar(StarParam param)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //点赞用户
            T_User user = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "点赞用户信息不存在~", null);
            //被点赞用户
            T_User uuser = operateContext.bllSession.T_User.FindSingle(s => s.user_id==param.id);
            if (uuser == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "被点赞用户信息不存在~", null);
            var query = operateContext.bllSession.T_VLineUserUserStar.FindSingle(s => s.user_guid.Equals(user.user_guid) && s.star_guid.Equals(uuser.user_guid));
            if (query != null && param.star_status == 1)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "用户点赞信息保存成功~", null);
            if (param.star_status == 1)
            {
                #region 点赞
                user.star_num += 1;
                uuser.mark_star_num += 1;
                if (query != null)
                {
                    query.star_date = DateTime.Now;
                    operateContext.bllSession.T_VLineUserUserStar.Modify(query, s => s.id == query.id, "star_date");
                }
                else
                {
                    operateContext.bllSession.T_VLineUserUserStar.Add(new T_VLineUserUserStar
                    {
                        user_guid = user.user_guid,
                        star_guid = uuser.user_guid,
                        star_date = DateTime.Now
                    });
                }
                #endregion
            }
            else
            {
                #region 取消点赞
                if (query == null)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未点赞过~", null);
                user.star_num -= 1;
                uuser.mark_star_num -= 1;
                operateContext.bllSession.T_VLineUserUserStar.Delete(s => s.id == query.id);
                #endregion
            }
            operateContext.bllSession.T_User.Modify(user, s => s.user_id == user.user_id, "star_num");
            operateContext.bllSession.T_User.Modify(uuser, s => s.user_id == uuser.user_id, "mark_star_num");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "用户点赞信息保存成功~", null);
        }
        #endregion

        #region 1.10 ✔保存位置记录 + WebApiResultJsonModel SaveGPS(AddGPS param)
        /// <summary>
        ///  1.10 ✔保存位置记录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveGPS(AddGPS param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var du = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (du == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户尚未保存度度圈信息！", "");
            var dt = DateTime.Now;
            int mark = operateContext.bllSession.DD_GPS.Add(new DD_GPS
            {
                du_id = param.user_id,
                created_time = dt,
                gps_x = param.gps_x,
                gps_y = param.gps_y,
                province = param.province,
                city = param.city,
                cityCode = param.cityCode,
                district = param.district,
                street = param.street,
                streetnumber = param.streetnumber,
                address = param.address
            });
            if (mark > 0)
            {
                operateContext.bllSession.DD_User.Modify(new DD_User { gps_x = param.gps_x, gps_y = param.gps_y, gps_time = dt, city = param.city, province = param.province, cityCode = param.cityCode, district = param.district, street = param.street, streetnumber = param.streetnumber, address = param.address }, s => s.du_id == param.user_id, "gps_x", "gps_y", "gps_time", "province", "city", "cityCode", "district", "street", "streetnumber", "address");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "位置保存成功！", "");
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "位置保存失败！", "");
        }
        #endregion

        #region 1.11 ✔保存个人信息 + WebApiResultJsonModel SaveUserInfo(ModifyUserInfo param)
        /// <summary>
        ///  1.11 ✔保存个人信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveUserInfo(ModifyUserInfo param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            bool isAdd = false;
            var u = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id);
            if(u==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户id后台不存在！", "");
            var du = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            u.user_birth = (!string.IsNullOrEmpty(param.user_birth) ? DateTime.ParseExact(param.user_birth, "yyyy-MM-dd", new System.Globalization.CultureInfo("zh-CN")) : (DateTime?)null);
            operateContext.bllSession.T_User.Modify(u, s => s.user_id == param.user_id, "user_birth");
            if (du == null)
            {
                isAdd = true;
                du = new DD_User();
            }
            if (param.du_city_id > 0)
            {
                var city = operateContext.bllSession.T_VRAreaInfo.FindSingle(s => s.area_id == param.du_city_id);
                if (city != null)
                    du.du_city = city.area_url.Trim();
            }
            if (param.du_hometown_id > 0)
            {
                var hometown = operateContext.bllSession.T_VRAreaInfo.FindSingle(s => s.area_id == param.du_hometown_id);
                if (hometown != null)
                    du.du_hometown = hometown.area_url.Trim();
            }
            du.du_name = param.du_name;
            du.du_sex = param.du_sex;
            du.du_city_id = param.du_city_id;
            du.du_hometown_id = param.du_hometown_id;
            du.du_prof = param.du_prof;
            du.du_school = param.du_school;
            du.du_signature = param.du_signature;
            du.update_time = DateTime.Now;
            int mark;
            //添加
            if (isAdd)
            {
                du.du_id = param.user_id;
                du.dd_verify = true;
                du.hide_city = 2;
                du.hide_hometown = 2;
                du.created_time = DateTime.Now;
                mark = operateContext.bllSession.DD_User.Add(du);
            }else //编辑
                mark = operateContext.bllSession.DD_User.Modify(du, s => s.du_id == param.user_id, "du_name", "du_sex", "du_city_id", "du_hometown_id", "du_prof", "du_school", "du_signature", "update_time", "du_city", "du_hometown");
            if (mark > 0)
            {
                operateContext.bllSession.T_User.Modify(new T_User { user_note = param.du_signature }, s => s.user_id == param.user_id, "user_note");
                #region 判断新职业基础数据
                if (!string.IsNullOrEmpty(param.du_prof))
                {
                    var obj = operateContext.bllSession.T_VRDDCircleBaseProf.FindSingle(s => s.du_prof.Equals(param.du_prof));
                    if (obj == null)
                        operateContext.bllSession.T_VRDDCircleBaseProf.Add(new T_VRDDCircleBaseProf { du_prof = param.du_prof, du_num = 1, create_date = DateTime.Now, update_date = DateTime.Now });
                    else
                        operateContext.bllSession.T_VRDDCircleBaseProf.Modify(new T_VRDDCircleBaseProf { du_num = obj.du_num + 1 }, s => s.id == obj.id, "du_num");
                }
                #endregion
                #region 判断更新学校基础数据
                if (!string.IsNullOrEmpty(param.du_school))
                {
                    var obj = operateContext.bllSession.T_VRDDCircleBaseSchool.FindSingle(s => s.du_school.Equals(param.du_school));
                    if (obj == null)
                        operateContext.bllSession.T_VRDDCircleBaseSchool.Add(new T_VRDDCircleBaseSchool { du_school = param.du_school, du_num = 1, create_date = DateTime.Now, update_date = DateTime.Now });
                    else
                        operateContext.bllSession.T_VRDDCircleBaseSchool.Modify(new T_VRDDCircleBaseSchool { du_num = obj.du_num + 1 }, s => s.id == obj.id, "du_num");
                }
                #endregion
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "个人信息保存成功！", "");
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "个人信息保存失败！", "");
        }
        #endregion

        #region 1.12 ✔保存隐私设置 + WebApiResultJsonModel SaveUserPrivacy(ModifyUserPrivacy param)
        /// <summary>
        ///  1.12 ✔保存隐私设置
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveUserPrivacy(ModifyUserPrivacy param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var du = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (du == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户尚未保存度度圈信息！", "");
            du.dd_verify = param.dd_verify;
            du.dd_hidden = param.dd_hidden;
            du.hide_name = param.hide_name;
            du.hide_sex = param.hide_sex;
            du.hide_mobile = param.hide_mobile;
            du.hide_birthday = param.hide_birthday;
            du.update_time = DateTime.Now;
            int mark = operateContext.bllSession.DD_User.Modify(du, s => s.du_id == param.user_id, "dd_verify", "dd_hidden", "hide_name", "hide_sex", "hide_mobile", "hide_birthday", "update_time");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "隐私设置保存成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "隐私设置保存失败！", "");
        }
        #endregion

        #region 1.13 ✔匹配手机好友 + WebApiResultJsonModel GetFriendByPhone(QueryFriendPhone param)
        /// <summary>
        ///  1.13 ✔匹配手机好友
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutFriendPhone>> GetFriendByPhone(QueryFriendPhone param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutFriendPhone>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(param.user_id<=0 && string.IsNullOrEmpty(param.userid))
                return ApiResultJsonModel<List<OutFriendPhone>>.RedirectWebApi(WebResultCode.Exception, "用户信息异常！", null);
            if (!string.IsNullOrEmpty(param.userid))
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            List<OutFriendPhone> list = operateContext.bllSession.DD_FriendApply.GetFriendByPhone(param);
            return ApiResultJsonModel<List<OutFriendPhone>>.RedirectWebApi(WebResultCode.Ok, "获取手机好友列表成功！", list);
        }
        #endregion

        #region 1.14 ✔我附近的人 + WebApiResultJsonModel GetUserByMyNearby(QueryNearbyUser param)
        /// <summary>
        ///  1.14 ✔我附近的人
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>Nearby
        [HttpPost]
        public WebApiResultJsonModel<List<OutNearbyUser>> GetUserByMyNearby(QueryNearbyUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutNearbyUser>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel<List<OutNearbyUser>>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息！", null);
            if (user.gps_x==null || user.gps_y==null)
                return ApiResultJsonModel<List<OutNearbyUser>>.RedirectWebApi(WebResultCode.Exception, "当前登录用户尚未保存最新gps位置信息！", null);
            List<OutNearbyUser> list = operateContext.bllSession.DD_User.GetUserByMyNearby(param, (decimal)user.gps_x, (decimal)user.gps_y);
            return ApiResultJsonModel<List<OutNearbyUser>>.RedirectWebApi(WebResultCode.Ok, "成功获取我附近的人~", list);
        }
        #endregion

        #region 1.15 ✔获取我的隐私设置 + WebApiResultJsonModel GetMyPrivateInfo(DDBaseUser param)
        /// <summary>
        ///  1.15 ✔获取我的隐私设置
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<OutMyPrivateInfo> GetMyPrivateInfo(DDBaseUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutMyPrivateInfo>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == param.user_id);
            if (user == null)
                return ApiResultJsonModel<OutMyPrivateInfo>.RedirectWebApi(WebResultCode.Exception, "当前登录对象尚未完善度度圈个人信息设置！", null);
            OutMyPrivateInfo result = new OutMyPrivateInfo
            {
                user_id = param.user_id,
                dd_verify = user.dd_verify,
                dd_hidden = user.dd_hidden,
                hide_name = user.hide_name,
                hide_sex = user.hide_sex,
                hide_mobile = user.hide_mobile,
                hide_birthday = user.hide_birthday
            };
            return ApiResultJsonModel<OutMyPrivateInfo>.RedirectWebApi(WebResultCode.Ok, "成功获取我的隐私设置~", result);
        }
        #endregion

        #region 1.16 ✔修改用户备注【签名】 + WebApiResultJsonModel ModifyUserNote(InputUserNote param)
        /// <summary>
        ///  1.16 ✔修改用户备注【签名】
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyUserNote(InputUserNote param)
        {
            //1.0 验证数据有效性
            if (param.user_id<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "请正确输入用户id！", null);
            int mark = operateContext.bllSession.T_User.SelectCount(s => s.user_id == param.user_id);
            if(mark<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前传递用户已删除或不存在！", null);
            operateContext.bllSession.T_User.Modify(new T_User { user_note = param.user_note }, s => s.user_id == param.user_id, "user_note");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "备注保存成功！", "");
        }
        #endregion

        #region 1.17 ✔获取未处理的好友申请数目 + WebApiResultJsonModel GetApplyFirendNum(BaseDDAPI param)
        /// <summary>
        ///  1.17 ✔获取未处理的好友申请数目
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<int?> GetApplyFirendNum(BaseDDAPI param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            if(user_id<=0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "请检查用户内部编码信息异常！", null);
            int num = operateContext.bllSession.DD_FriendApply.SelectCount(s => s.du_id == user_id && s.apply_status == -1);
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, "成功获取未处理的好友申请数目~", num);
        }
        #endregion

        #region 1.18 ✔设为或取消蜜友 + WebApiResultJsonModel SetCloseFriend(CloseFriendInput param)
        /// <summary>
        ///  1.18 ✔设为或取消蜜友
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.2 需求<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel SetCloseFriend(CloseFriendInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int d1 = SysPermissSession.ChangeIdByGuid(param.userid),
                d2 = SysPermissSession.ChangeIdByGuid(param.friendID),
                mark = 0;
            if (d1<=0 || d2<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户编码数据异常！", null);
            //判断数据是否存在
            var f = operateContext.bllSession.DD_1.FindSingle(s => s.dd_id_1 == d1 && s.dd_id_2 == d2);
            if(f==null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "非好友关系不能设置/取消密友！", null);
            //设为密友
            if (param.status == 1)
            {
                //if(f.status)
                //    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已是密友关系！", null);
                string codeName = operateContext.bllSession.DD_1.GetDictName("CloseFriendType", Helper.ToString(param.type));
                mark = operateContext.bllSession.DD_1.Modify(new DD_1 { status = true, closeType = Helper.ToString(param.type), closeName = codeName }, s => s.primary_key == f.primary_key, "status", "closeType", "closeName");
            }
            else
            {
                //取消密友
                //if(!f.status)
                //    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已取消密友关系！", null);
                mark = operateContext.bllSession.DD_1.Modify(new DD_1 { status = false, closeType = null, closeName = null }, s => s.primary_key == f.primary_key, "status", "closeType", "closeName");
            }
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "设为或取消蜜友成功~", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "设为或取消蜜友失败！", null);
        }
        #endregion

        #region 1.19 ✔保存好友备注 + WebApiResultJsonModel SaveFriendNote(FriendNoteInput param)
        /// <summary>
        ///  1.19 ✔保存好友备注
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.3 需求<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel SaveFriendNote(FriendNoteInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int d1 = SysPermissSession.ChangeIdByGuid(param.userid),
                d2 = SysPermissSession.ChangeIdByGuid(param.friendID);
            if (d1 <= 0 || d2 <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户编码数据异常！", null);
            //判断数据是否存在
            var f = operateContext.bllSession.DD_1.FindSingle(s => s.dd_id_1 == d1 && s.dd_id_2 == d2);
            if (f == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "非好友关系不能保存好友备注！", null);
            operateContext.bllSession.DD_1.Modify(new DD_1 { friendNote = param.friendNote, friendDescribe = param.friendDescribe }, s => s.primary_key == f.primary_key, "friendNote", "friendDescribe");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "保存好友备注成功~", "");
        }
        #endregion

        //****************************************************2021-05-31需求*******************************************************

        #region 2.1 ✔修改用户名 + WebApiResultJsonModel ModifyUserName(InputUserName param)
        /// <summary>
        ///  2.1 ✔修改用户名
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyUserName(InputUserName param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_User.SelectCount(s => s.user_id == param.user_id);
            if(mark<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户信息不存在！", "");
            mark = operateContext.bllSession.T_User.Modify(new T_User { user_name = param.user_name }, s => s.user_id == param.user_id, "user_name");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "用户名修改成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户名修改失败！", "");
        }
        #endregion

        #region 2.5 ✔获取职业基础信息 + WebApiResultJsonModel GetBaseProf(InputBaseProf param)
        /// <summary>
        ///  2.5 ✔获取职业基础信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputBaseProf>> GetBaseProf(InputBaseProf param)
        {
            List<OutputBaseProf> list = new List<OutputBaseProf>();
            List<T_VRDDCircleBaseProf> result;
            if (!string.IsNullOrEmpty(param.keyword))
                result = operateContext.bllSession.T_VRDDCircleBaseProf.Select(s => s.du_prof.Contains(param.keyword)).OrderByDescending(s => s.du_num).OrderByDescending(s => s.create_date)?.ToList();
            result = operateContext.bllSession.T_VRDDCircleBaseProf.Select(s => true).OrderByDescending(s => s.du_num).OrderByDescending(s => s.create_date)?.ToList();
            result?.ForEach(s => list.Add(new OutputBaseProf { name = s.du_prof, du_num = s.du_num }));
            return ApiResultJsonModel<List<OutputBaseProf>>.RedirectWebApi(WebResultCode.Ok, "成功获取职业基础信息列表~", list);
        }
        #endregion

        #region 2.6 ✔获取学校基础信息 + WebApiResultJsonModel GetBaseProf(InputBaseProf param)
        /// <summary>
        ///  2.6 ✔获取学校基础信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputBaseProf>> GetBaseSchool(InputBaseProf param)
        {
            List<OutputBaseProf> list = new List<OutputBaseProf>();
            List<T_VRDDCircleBaseSchool> result;
            if (!string.IsNullOrEmpty(param.keyword))
                result = operateContext.bllSession.T_VRDDCircleBaseSchool.Select(s => s.du_school.Contains(param.keyword)).OrderByDescending(s => s.du_num).OrderByDescending(s => s.create_date)?.ToList();
            result = operateContext.bllSession.T_VRDDCircleBaseSchool.Select(s => true).OrderByDescending(s => s.du_num).OrderByDescending(s => s.create_date)?.ToList();
            result?.ForEach(s => list.Add(new OutputBaseProf { name = s.du_school, du_num = s.du_num }));
            return ApiResultJsonModel<List<OutputBaseProf>>.RedirectWebApi(WebResultCode.Ok, "成功获取学校基础信息列表~", list);
        }
        #endregion

        #region 2.7 ✔更新用户性别 + WebApiResultJsonModel ModifyUserSex(InputModifySex param)
        /// <summary>
        ///  2.7 ✔更新用户性别
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyUserSex(InputModifySex param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_User.SelectCount(s => s.user_guid == param.userID);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前传递用户已删除或不存在！", null);
            operateContext.bllSession.T_User.Modify(new T_User { user_sex = param.userSex }, s => s.user_guid == param.userID, "user_sex");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "用户信息修改成功！", "");
        }
        #endregion

        //****************************************************2022-05-31需求*******************************************************
        #region 3.0 ✔删除好友 + WebApiResultJsonModel DeleteFriend(DeleteFriendInput param)
        /// <summary>
        ///  3.0 ✔删除好友
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.6 需求<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel DeleteFriend(DeleteFriendInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int d1 = SysPermissSession.ChangeIdByGuid(param.userid),
                d2 = SysPermissSession.ChangeIdByGuid(param.friendID);
            if (d1 <= 0 || d2 <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户编码数据异常！", null);
            //判断数据是否存在
            var f = operateContext.bllSession.DD_1.FindSingle(s => s.dd_id_1 == d1 && s.dd_id_2 == d2);
            if (f == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "非好友关系无需删除！", null);
            int mark = operateContext.bllSession.DD_1.Delete(s => s.dd_id_1 == d1 && s.dd_id_2 == d2);
            if (mark > 0)
            {
                //更新好友状态
                operateContext.bllSession.DD_1.Modify(new DD_1 { isfriend = false }, s => s.dd_id_1 == d2 && s.dd_id_2 == d1, "isfriend");
                //删除好友申请、以便重新申请
                operateContext.bllSession.DD_FriendApply.Delete(s => (s.du_id == d1 && s.apply_id == d2) || (s.du_id == d2 && s.apply_id == d1));
                //自动更新2度、3度人脉
                operateContext.bllSession.DD_FriendApply.UpdateDD2(d1, d2);
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "删除好友成功~", "");
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "删除好友失败！", null);   
        }
        #endregion

        #region 3.1 ✔获取好友状态 + WebApiResultJsonModel GetFriendStatus(DeleteFriendInput param)
        /// <summary>
        ///  3.1 ✔获取好友状态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.7 需求<br/>
        /// 好友状态：1=是对方的好友；0=不是对方的好友
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<int?> GetFriendStatus(DeleteFriendInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int d1 = SysPermissSession.ChangeIdByGuid(param.userid),
                d2 = SysPermissSession.ChangeIdByGuid(param.friendID);
            if (d1 <= 0 || d2 <= 0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "用户编码数据异常！", null);
            //判断数据是否存在
            var f = operateContext.bllSession.DD_1.FindSingle(s => s.dd_id_1 == d1 && s.dd_id_2 == d2);
            if (f == null)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "非好友关系无法获取状态！", null);
            int mark = operateContext.bllSession.DD_1.SelectCount(s => s.dd_id_1 == d2 && s.dd_id_2 == d1);
            mark = mark > 0 ? 1 : 0;
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, "获取好友状态成功~", mark);
        }
        #endregion

        #region 3.2 ✔获取人脉列表 + WebApiResultJsonModel GetConnectionList(ConnectionListInput param)
        /// <summary>
        ///  3.2 ✔获取人脉列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<ConnectionListOutput>> GetConnectionList(ConnectionListInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<ConnectionListOutput>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if(param.duidList==null || param.duidList.Count<=0)
                return ApiResultJsonModel<List<ConnectionListOutput>>.RedirectWebApi(WebResultCode.Exception, "请传递好友用户编码列表参数！", null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            var result = operateContext.bllSession.DD_FriendApply.GetConnectionList(param, user_id);
            return ApiResultJsonModel<List<ConnectionListOutput>>.RedirectWebApi(WebResultCode.Ok, "成功获取人脉列表！", result);
        }
        #endregion

        #region 3.3 ✔获取我的蜜友类别 + WebApiResultJsonModel GetMyCloseType (BaseParam param)
        /// <summary>
        ///  3.2 ✔获取我的蜜友类别
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、禅道需求 id=【335】<br/>
        /// </remarks> 
        [HttpPost]
        public WebApiResultJsonModel<List<OutputMyCloseType>> GetMyCloseType(BaseParam param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputMyCloseType>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            var list = operateContext.bllSession.DD_FriendApply.GetMyCloseType(user_id);
            return ApiResultJsonModel<List<OutputMyCloseType>>.RedirectWebApi(WebResultCode.Ok, "成功获取我的蜜友类别！", list);
        }
        #endregion

        #region 3.3 ✔获取用户类别 + WebApiResultJsonModel GetUserType(UserTypeInput param)
        /// <summary>
        ///  3.3 ✔获取用户类别
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、2022-05-30 1.2 需求<br/>
        /// 返回值：0=普通用户；1=VIP用户
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<int?> GetUserType(UserTypeInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userID);
            if (user_id <= 0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "用户编码数据异常！", null);
            var user = operateContext.bllSession.DD_User.FindSingle(s => s.du_id == user_id);
            if(user==null)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "当前用户不存在度度圈账户信息！", null);
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, "获取用户类别成功~", user.user_type > 0 ? 1 : 0);
        }
        #endregion
    }
}